package com.jiayi.weiphoto.activity;

import java.io.File;

import com.jiayi.weiphoto.R;
import com.jiayi.weiphoto.net.Util;
import com.jiayi.weiphoto.util.StringUtil;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class QrCodeActivity extends MyBaseActivity{
	
	Button bt_back_qrcode=null;
	ImageView qrCodeImg;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.qrcode);
		bt_back_qrcode=(Button) findViewById(R.id.bt_back_qrcode);
		bt_back_qrcode.setOnClickListener(this);
		qrCodeImg = (ImageView) findViewById(R.id.img_qrcode);
		Bitmap qrBitmap = getQrBitmap();
		qrCodeImg.setImageBitmap(qrBitmap);
	}

	private Bitmap getQrBitmap() {
		// TODO Auto-generated method stub
		Bitmap qrBitmap = null;
		File qrFile = new File(StringUtil.genQrCodePath(QrCodeActivity.this));
		if(qrFile.exists()){
			qrBitmap = BitmapFactory.decodeFile(qrFile.getAbsolutePath());
		}else{
			qrBitmap = Util.initQrcode(mContext);
		}
		return qrBitmap;
	}

	@Override
	public void onClick(View v) {
		finish();
	}

}
